One of AppMaker's most useful features is the ability to define the data structures that you will use to implement the functional logic of your application. You can define data classes and data items and you can connect user interface items to data items.
AppMaker generates code for:
You can provide code fragments which will be inserted in the appropriate place in the generated code. This lets you write much of your application logic inside AppMaker. If you later regenerate code, your code fragments will be preserved.
To define your data, you first create Data Defs (Data Definitions) then you create Members within Data Defs. Later, you connect windows and dialogs to Data Defs and you connect UI items to data items (members) using Item Info dialogs or the Info floater.
You can define your data before or after you define your user interface. You can even have AppMaker define data for you. If you define only your user interface but not your data, then you generate code, AppMaker will automatically create Data Defs and Members and will connect UI items to data items. Afterwards you can modify these Data Defs and their Members, and connect UI items to data items of your choice.
To create a Data Def, select the Data Defs category in your main window. Then choose Create Data Def from the Edit menu. AppMaker displays the Data Def Info dialog. Enter a Title which will form an identifier in the generated code. Leave the other options blank. They are not currently used. (At one time we thought we would use them for the NeoAccess library.)
After creating Data Defs, you can then create Data Members. Select a Data Def, Then choose Create Member from the Edit menu. AppMaker displays a Member Info dialog.
Kind and Type are closely related. Choose a Kind from the popup to specify the behavior of the data member. Available choices include Integer, Boolean, Pascal String, and several others. The Type field specifies a particular representation, e.g. 32-bit signed integer or 8-bit unsigned integer. You can choose a Type using the small popup to the right of the field or you can type directly into the Edit Field.
The "Is Array" checkbox lets you specify that the Member is an array of the specified Kind and Type. Currently it is implemented only for the Kind, "Reference to DataDef". The AMReminder example has an array of Reminders. Each element of the array is a pointer to an object of type DReminder, which was generated from the Reminder Data Def.
The Flavor popup lets you choose Data, Pseudo-data, Persistent Data, or Function. Data, Pseudo-data, and Persistent Data all have Get and Set accessor functions. AppMaker generates Get and Set functions and allows you to specify code fragments to be inserted in these functions. The difference between Data and Pseudo-data is that Pseudo-data is not actually stored in memory; it is calculated from other data. The Get code calculates a value from other data members. The Set code can store into other members. Persistent data is stored in memory and also in a file. AppMaker generates code to read and write the data in response to Open and Save commands. The Function flavor lets you specify function members, not just data members, in the generated data classes. You can call these functions from other data members or from Command code fragments.
The Initial Value field lets you specify a numeric or string value as appropriate. If you don't specify a value, AppMaker will generate code to initialize numbers to zero, booleans to false, strings to empty, pointers to nil, and dateTimes to today and now.
The "Get" code and "Set" code fields let you specify code fragments which will be inserted in the generated code. For Data or Persistent data you do not need to specify a code fragment. AppMaker will generate code to return the value of the stored data member and to store into the data member. You might add code to effect relationships among data members, i.e. if one data member depends on other members. For pseudo-data you should always write Get and/or Set code fragments. You might write only Get or only Set if you know that your application doesn't need both Get and Set.
For a member with Flavor Function, the Function body field lets you specify a code fragment which will be inserted in the generated code.
The Extra Include Names field lets you enter the names of #include fields that will be inserted into the generated code so that your code fragments can compile correctly. In the AMReminder example we included an Apple header file, DateTimeUtils. For your application you could include your own header files so that your code fragments could access functions you write outside of AppMaker.
Within AppMaker you can connect Windows and Dialogs to Data Defs and Window Items to Members. AppMaker will do much of this for you if you do not do it manually. You will normally connect the Document and all the Windows to a Data Def which is by convention named DocData. You will normally connect each Dialog to a separate DataDef for each Dialog. The Document Info, Window Info, and Dialog Info dialogs let you choose a DataDef from a popup.
Most Window Items should be connected to data Members so that the UI can display and change data values. Multiple UI items can be connected to the same data item. In the Temperature example, an Edit Text item and a Scroll Bar are connected to the same temperature data. In the LayerGroups example, a List and a Layer Group are connected to the same data so that selecting from the List changes which layer is displayed in the Layer Group.
You connect a Window Item to a data Member either by the item's info dialog (e.g. the Checkbox Info dialog or the EditText Info dialog) or by the Info floater.
The Target Data popup lets you choose a Data Def and a Member. You should choose the same Data Def that the Window or Dialog is connected to, but if that Data Def has a Member whose Kind is "Reference to Data Def" then you can navigate through that Member to access Members of the other Data Def.
There is a second kind of connection between a Window item and a data item. In the Info floater you can use the Enabling Data popup to connect the Window Item to a boolean data item which will control whether the Window Item is enabled or disabled. You can write "Set" code in other data members to change the enabled/disabled state depending on the values of various data members.
In the generated code, AppMaker uses a few simple naming conventions: